﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace observerPatternSample
{
    public class calculator: iSubject
    {
        public ArrayList observers;
        float num1;
        float num2;

        public calculator()
        {
            observers = new ArrayList();
        }

        public void notify()
        { 
               for(int c = 0; c < observers.Count; c++)
                {
                    iObserver observer = (iObserver)observers[c];
                    observer.update(num1, num2);
                }
                 
        }

        public void register(iObserver observer)
        {
            observers.Add(observer);
        }

        public void unregister(iObserver observer)
        {
            observers.Remove(observer);
        }

        public void changeValues()
        {
            notify();
        }

        public void setValues( float num1, float num2)
        {
            this.num1 = num1;
            this.num2 = num2;
            
            changeValues();
        }
    }
}
